package leetcode100;


import java.util.LinkedList;

public class lc007 {

    public static void main(String[] args) {
        Tree tree = new Tree();
        tree.visit();
        TreeNode root = tree.root;
        TreeNode res = invertTree(tree,root);
        tree.root = res;
        tree.visit();
    }

    public static TreeNode invertTree(Tree tree,TreeNode root) {
        if(root==null) return null;
        LinkedList<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()) {
//            System.out.println(queue);
//            tree.visit();
            TreeNode parent = queue.poll();
            TreeNode right = parent.left;
            TreeNode left = parent.right;
            parent.left = left;
            parent.right = right;
            if (left != null)
                queue.add(left);
            if (right != null)
                queue.add(right);

        }
        return root;
    }
}
